<template>
  <div>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>候选人列表</span>
      </div>
      <el-form :inline="true" :model="form">
        <el-form-item label="姓名">
          <el-input v-model="form.realName"></el-input>
        </el-form-item>
        <el-form-item label="手机号">
          <el-input v-model="form.mobile"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="search">搜索</el-button>
        </el-form-item>
      </el-form>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="id" label="ID"></el-table-column>
        <el-table-column prop="realName" label="应聘者姓名"></el-table-column>
        <el-table-column prop="identityNum" label="身份证号码"></el-table-column>
        <el-table-column  label="性别">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.sex==1" type="success"><b>男</b></el-tag>
            <el-tag v-else-if="scope.row.sex==0" type="danger">女</el-tag>
            <el-tag v-else type="warning">未知</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="mobile" label="手机号"></el-table-column>
        <el-table-column prop="email" label="邮箱"></el-table-column>
        <el-table-column prop="birthday" label="出生日期"></el-table-column>
        <el-table-column prop="jobName" label="面试岗位"></el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next"
            :total="total">
        </el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>

import http from '@/http.js'; // 导入封装好的axios实例

export default {
  data() {
    return {
      form: {
        realName: '',
        mobile: '',
        pageSize: 10,
        pageNumber: 1
      },
      tableData: [],
      currentPage: 1,
      pageSize: 10,
      total: 0
    };
  },
  mounted() {
    this.getCandidateList();
  },
  methods: {
    search() {
      // 这里可以添加搜索逻辑，例如发送请求获取数据
      console.log('执行搜索操作，姓名：', this.form.name, '手机号：', this.form.phone);
      this.form.pageSize=10
      this.form.pageNumber=1
      this.getCandidateList();
    },
    handleSizeChange(size) {
      this.form.pageSize = size;
      this.getCandidateList();
    },
    handleCurrentChange(page) {
      this.form.pageNumber = page;
      this.getCandidateList();
    },
    getCandidateList() {
      http.post('/candidate/list', this.form).then(res => {
        console.log(res)

        this.tableData = res.records;
        this.total = res.total;

      })
    }
  }
};
</script>

<style scoped>
.pagination {
  text-align: right;
}
</style>